ValueFolderTemp='/sps/isc/rneveu/EtudeIRM/Nature/ResultsJournal/';
ValueFolderTemp2='/sps/isc/rneveu/EtudeIRM/Nature/ResultsEditor/';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
VecValueTime=[0 2 1 5 10 3 4];
VecValueFilter=[0 1];
ValueFolder2='/sps/isc/rneveu/EtudeIRM/Nature/';
load([ValueFolder2 'EtudeNature.mat']);
VecEditors1Temp(1,:)=[];
[VecResultsMean1,VecResultsMean2,VecResultsMean3]=ComputeMean(VecEditors1Temp);
ValueCutoff=1.25;
for n5=1:size(VecValueTime,2)
    for n6=1:size(VecValueFilter,2)
        ValueTime=VecValueTime(1,n5);
        ValueFilter=VecValueFilter(1,n6);
        VecValueFigure=[];
        for n1=1:33
            if ValueTime>=1
                if ValueFilter==0
                    ValueFile=['FileAnalysis' num2str(ValueTime) 'Journal' num2str(n1) '.mat'];
                else
                    ValueFile=['FileAnalysis' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                end
            else
                if ValueFilter==0
                    ValueFile=['FileAnalysisJournal' num2str(n1) '.mat'];
                else
                    ValueFile=['FileAnalysisFiltered' num2str(ValueFilter) 'Journal' num2str(n1) '.mat'];
                end
            end
            ValueFileTemp=dir([ValueFolderTemp ValueFile]);
            if size(ValueFileTemp,1)==1
                load([ValueFolderTemp ValueFile]);
                n2=1;
                TestTemp=0;
                while n2<=size(VecResultsArticle2,1)&&TestTemp==0
                    if VecResultsArticle2(n2,4)>0
                        TestTemp=1;
                    end
                    n2=n2+1;
                end
                VecValueTemp=VecResultsArticle2(n2-1:end,:);
                for n4=1:323
                    ValueTemp=find(VecDistribution(:,1)==n4);
                    if n4~=11&&size(ValueTemp,1)==1&&VecDistribution(ValueTemp(1,1),2)<=ValueCutoff
                        load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n4) '.mat']);
                        if isnan(VecResultsEditor(1,11))==1
                            VecResultsEditor(1,11)=VecResultsMean2(1,end);
                        end
                        if isnan(VecResultsEditor(1,12))==1
                            VecResultsEditor(1,12)=VecResultsMean1(1,end);
                        end
                        if isnan(VecResultsEditor(1,27))==1
                            VecResultsEditor(1,27)=VecResultsMean1(1,end)+VecResultsMean2(1,end);
                        end
                        ValueTemp4=VecEditors1Temp{n4,4};
                        ValueTemp5=VecEditors1Temp{n4,6};
                        if ischar(ValueTemp4)==1
                            ValueTemp4=str2double(ValueTemp4);
                        end
                        if ischar(ValueTemp5)==1
                            ValueTemp5=str2double(ValueTemp5);
                        end
                        if isnan(ValueTemp4)==0||isnan(ValueTemp5)==0
                            if VecResultsEditor(1,39)==n1&&VecResultsEditor(1,1)<40 % We remove the editor who has more than 40 article spublished
                                if isnan(ValueTemp4)==0&&isnan(ValueTemp5)==0
                                    if ValueTemp5>ValueTemp4
                                        ValueStartYear=VecEditors1Temp{n4,5};
                                    else
                                        ValueStartYear=VecEditors1Temp{n4,3};
                                    end
                                else
                                    if isnan(ValueTemp4)==0
                                        ValueStartYear=VecEditors1Temp{n4,3};
                                    else
                                        ValueStartYear=VecEditors1Temp{n4,5};
                                    end
                                end
                                ValueTemp4=find(ValueStartYear=='/');
                                ValueStartYear=str2double(ValueStartYear(1,ValueTemp4(1,end)+1:end));
                                if ValueStartYear<1990
                                    ValueStartYear=1990;
                                end
                                VecValueTemp3=[2020-ValueStartYear;size(VecValueTemp,1)];
                                n2Temp=min(VecValueTemp3);
                                VecValue2Temp=VecResultsArticle1(n2-1:end,:);
                                VecResults2=VecValueTemp;
                                VecValueTemp2=1:size(VecValueTemp,1);
                                VecValueTemp2=VecValueTemp2';
                                VecValueTemp2=VecValueTemp2-1;
                                if size(VecValueTemp2,1)>2
                                    VecValueTemp5=[VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),3)./VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),4)*100 VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),1)./VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),3)*100 VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),2)./VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),3)*100];
                                    VecValueTemp51=[VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),3)./VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),4)*100 VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),1)./VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),3)*100 VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),2)./VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),3)*100];
                                    ValueTemp5=find(VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),4)==0);
                                    VecValueTemp5(ValueTemp5,:)=NaN(size(ValueTemp5,1),3);
                                    ValueTemp5=find(VecValueTemp(size(VecValueTemp,1)-n2Temp+1:size(VecValueTemp,1),3)==0);
                                    VecValueTemp5(ValueTemp5,:)=NaN(size(ValueTemp5,1),3);
                                    ValueTemp5=find(VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),4)==0);
                                    VecValueTemp51(ValueTemp5,:)=NaN(size(ValueTemp5,1),3);
                                    ValueTemp5=find(VecValue2Temp(size(VecValue2Temp,1)-n2Temp+1:size(VecValue2Temp,1),3)==0);
                                    VecValueTemp51(ValueTemp5,:)=NaN(size(ValueTemp5,1),3);
                                    VecValueTimeTemp=1:size(VecValueTemp5,1);
                                    VecValueTimeTemp=VecValueTimeTemp-size(VecValueTimeTemp,2);
                                    VecValueTimeTemp=VecValueTimeTemp';
                                    VecValueFigure=[VecValueFigure;VecValueTemp5 n1*ones(size(VecValueTemp5,1),1) n4*ones(size(VecValueTemp5,1),1) VecValueTemp51 VecValueTimeTemp repmat(VecResultsEditor,size(VecValueTemp5,1),1)];
                                end
                            end
                        end
                    end
                end
            end
        end
        ValueTemp=find(isnan(VecValueFigure(:,1))==1);
        VecValueFigure(ValueTemp,:)=[];
        % AnalyseMixedModelJournalTimeXXFilteredXXAllEditors.mat contains the research experience duration without replacing missing values by the mean computed for AnalyseCoAuthorsEditors.m and AnalyseMixedModelJournalTimeXXFitleredXXAllEditors2.mat contains the research epxerience with missing values replaced by the means
        save([ValueFolderTemp 'AnalyseMixedModelJournalTime' num2str(ValueTime) 'Filtered' num2str(ValueFilter) 'AllEditors2.mat'],'VecValueFigure');
    end
end
        